package com.celan.year2023.month07.day29;

import java.util.HashSet;

/**
 * @author Celan
 * @description TODO
 */
public class Solution {
    public boolean hasCycle(ListNode head) {
        HashSet<ListNode> set = new HashSet<>();
        ListNode p = head;
        while (p.next != null) {
            if (set.contains(p)) return true;
            set.add(p);
        }
        return false;
    }
}
